<?php
//输出文件地址
function wjdz($wenjiandizi) {
	
	echo '<table width="960" border="1" align="center" cellspacing="2">
		<tr>
			<td>
				<a href="index.php">返回首页
			</td>
			<td>';
			echo "文件下载地址：<a href=\"$wenjiandizi\">点我直接下载或者复制到下载工具
			</td>
			<td>
				<a href=\"gx.php\">提交新地址
			</td>
		";
	
	}
function GetIP(){ 
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) 
$ip = getenv("HTTP_CLIENT_IP"); 
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) 
$ip = getenv("HTTP_X_FORWARDED_FOR"); 
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) 
$ip = getenv("REMOTE_ADDR"); 
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) 
$ip = $_SERVER['REMOTE_ADDR']; 
else 
$ip = "unknown"; 
return($ip); 
} 


//百度解析
function baidu($url,$ip) {
$wangzhi=$url;
$iipp=$ip;
$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, "$url");
		curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-FORWARDED-FOR:$iipp", "CLIENT-IP:$iipp"));  //构造IP
		curl_setopt($ch, CURLOPT_REFERER,$iipp);   //构造来路
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$file = curl_exec($ch);
		

//echo $file;
$pattern='|dlink(.*?)sh=1\\\"|i';
preg_match_all($pattern,$file,$result,PREG_SET_ORDER );	

//var_dump($result);

$temp0=$result[0][0];
$temp1=$result[1][0];


if (strcasecmp($temp0,$temp1)==0)//两者相等返回0
		{
		$tempurl=$result[0][0];
			//echo $tempurl."<br>";
		$find = array('\\\\/', 'dlink\\":\\"');
			$replace = array('\\', '');
			$fileurlt1 = str_replace($find, $replace, $tempurl);
			echo $fileurlt1."<br>";
			$fileurl=$fileurlt;          //str_replace("2","43",$fileurlt);
			//echo $fileurl."<br>";
			wjdz($fileurl);
		}else {
				echo "dsfdsgfdsgsgsg";
		for($i=0;$result[$i][0]!=NULL;$i++)
			{
				$tempurl=$result[$i][0];
																		//echo $tempurl.""<br>";
																/*		$fileurlt1=str_replace("\\\\/","\\",$tempurl);
																		
																		$tempurlt2=str_replace("link","222222",$fileurlt1);
																		echo $fileurlt2."<br>";*/
			
			$find = array('\\\\/', 'dlink\\":\\"');
			$replace = array('\\', '');
			$fileurlt1 = str_replace($find, $replace, $tempurl);
			//echo $fileurlt1."<br>";
			$fileurl=$fileurlt1;       		   //str_replace("2","43",$fileurlt);
												//echo $fileurl."<br>";
			wjdz($fileurl);
												//header("location:$fileurl");
			} 
			

		}
}